package pers.qianyu.month_202012.date_20201203;

import org.junit.*;

import java.util.*;

/**
 * 452. 用最少数量的箭引爆气球
 * https://leetcode-cn.com/problems/minimum-number-of-arrows-to-burst-balloons/
 *
 * @author mizzle rain
 * @date 2020-12-03 17:40
 */
public class FindMinArrowShots {
    public int findMinArrowShots(int[][] points) {
        if (points == null || points.length == 0) {
            return 0;
        }
        Arrays.sort(points, (arr1, arr2) -> {
            long res = (long) arr1[1] - (long) arr2[1];
            if (res > 0) {
                return 1;
            } else if (res < 0) {
                return -1;
            } else {
                return 0;
            }
        });
        int res = 1, end = points[0][1];
        for (int[] point : points) {
            if (point[0] > end) {
                res++;
                end = point[1];
            }
        }
        return res;
    }

    @Test
    public void test4() {
        int[][] param = {{-2147483646, -2147483645}, {2147483646, 2147483647}};
        int result = new FindMinArrowShots().findMinArrowShots(param);
        System.out.println("result = " + result);
    }

    @Test
    public void test1() {
        int[][] param = {{10, 16}, {2, 8}, {1, 6}, {7, 12}};
        int result = new FindMinArrowShots().findMinArrowShots(param);
        System.out.println("result = " + result);
    }

    @Test
    public void test3() {
        int[][] param = {{10, 16}, {2, 8}, {1, 6}, {7, 12}};
        int result = new FindMinArrowShots().findMinArrowShots(param);
        System.out.println("result = " + result);
    }

    @Test
    public void test2() {
        int i = 0;
        for (; i < 10; i++) {
            if (i == 5) {
                break;
            }
        }
        System.out.println(i);
    }
}
